#include <iostream>
#include "testlogin.hpp"
#include "testregister.hpp"
#include "testnavigation.hpp"
#include "../Util/httplib.hpp"
#include "testcomment.hpp"
#include "testshopping.hpp"

using namespace httplib;



void Usage(std::string proc)
{
    std::cout << proc << " + port"  << std::endl;
}

// 导航栏
void test_navi()
{
    while(true)
    {
        string str;
        cin >> str;
        string s;
        bool ret = navi(str, s);
        if(!ret)
        {
            LOG(INFO) << "导航失败" << "\n";
        }
        cout << s << endl;
    }
}

// 评论
void test_comment()
{
    while(true)
    {
        string in;
        cin >> in;
        if(in == "quit") break;
        bool ret = send_comment(in);
        if(ret) LOG(INFO) << "评论成功" << "\n";
    }
    cout << "-------------" << endl;

    int n = 0;
    cout << "【1: 看评论 / 2: 直接退出】# ";
    cin >> n;
    string out;
    bool ret = recv_comment(out);
    cout << out;
    if(ret) LOG(INFO) << "查看评论成功" << "\n";
}

// 购物车
void test_shop()
{
    while(true)
    {
        cout << "请选择操作: ";
        int n = 0;
        cin >> n;
        if(n == 0) 
        {
            LOG(INFO) << "退出购物车" << "\n";
            break;
        }
        Shop sp;
        switch(n)
        {
        case 1:
            sp.insert();
            break;
        case 2:
            sp.showAll();
            break;
        case 3:
            sp.showById();
            break;
        case 4:
            sp.showByName();
            break;
        case 5:
            sp.delById();
            break;
        case 6:
            sp.delByName();
            break;
        case 7:
            sp.updateCount();
            break;
        default:
            LOG(INFO) << "未知操作, 请重试" << "\n";
            break;
        }
    }
}

int main(int argc, char* argv[])
{
    // if(argc != 2)
    // {
    //     Usage(argv[0]);
    //     exit(1);
    // }

    // Server svr;

    // // 注册
    // svr.Post("/reg", [](const Request& req, Response& resp){
    //     std::string in_json = req.body;
    //     std::string out_json;
    //     reg(in_json, out_json);
    //     resp.set_content(out_json, "application/json;charset=utf-8");
    // });

    // //登录
    // svr.Post("/login", [](const Request& req, Response& resp){
    //     std::string in_json = req.body;
    //     std::string out_json;
    //     login(in_json, out_json);
    //     resp.set_content(out_json, "application/json;charset=utf-8");
    // });

    // svr.listen("0.0.0.0", std::stoi(argv[1]));


    
    // 导航栏
    //test_navi();

    // 评论
    // test_comment();


    // 购物车
    test_shop();


    return 0;
}